@extends('layouts.home')
@section('title', '沃势管理后台')
@section('style')
    <link href="../plugins/timepicker/bootstrap-timepicker.min.css" rel="stylesheet">
    <link href="../plugins/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="../plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet">
    <link href="../plugins/clockpicker/css/bootstrap-clockpicker.min.css" rel="stylesheet">
    <link href="../plugins/bootstrap-daterangepicker/daterangepicker.css" rel="stylesheet">
    <!-- Plugins css-->
    <link href="../plugins/multiselect/css/multi-select.css"  rel="stylesheet" type="text/css" />
    <link href="../plugins/select2/css/select2.min.css" rel="stylesheet" type="text/css" />
    <link href="../plugins/bootstrap-select/css/bootstrap-select.min.css" rel="stylesheet" />
    <link href="../plugins/bootstrap-sweetalert/sweet-alert.css" rel="stylesheet" type="text/css">
@endsection
@section('content')
    <div class="row">
        <div class="col-sm-12">
            <div class="card-box">
                <div class="row">
                    <form action="{{route('setting.permission.index')}}" method="get">
                        <div class="col-sm-3">
                            <span class="input-group-btn">
                                <a class="btn btn-success waves-effect" href="{{ route('setting.permission.refresh') }}"><i class="glyphicon glyphicon-import"></i> 导入</a>
                                <a class="btn btn-primary waves-effect"><i class="glyphicon glyphicon-floppy-disk"></i> 保存</a>
                                <a class="btn btn-danger waves-effect deleteall" data-href="{{ route('setting.permission.destroy.all') }}"><i class="fa fa-trash-o"></i> 删除</a>
                            </span>
                        </div>
                    </form>
                </div>
            </div>
            <div class="card-box">

                <div class="table-rep-plugin">
                    <div class="table-responsive" data-pattern="priority-columns">
                        <form action="{{ route('setting.permission.save') }}" method="post" id="form">
                        <table class="tablesaw table m-b-0" data-tablesaw-mode="swipe" data-tablesaw-mode-switch data-tablesaw-minimap>
                            <thead>
                            <tr>
                                <th>显示名称</th>
                                <th>路由</th>
                                <th>图标</th>
                                <th>是否菜单</th>
                                <th>排序</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($menu as $m)
                            <tr>
                                <td><input type="text" class="form-control input-sm" name="name[{{ $m->id }}]" value="{{ $m->name }}" /></td>
                                <td>{!! $m->icon_html !!} {{ $m->namespace?:$m->namespace.'.'.$m->controller?:$m->controller.'.'.$m->action?:$m->action }}</td>
                                <td><input type="text" class="form-control input-sm" size="1" name="icon[{{ $m->id }}]" value="{{ $m->icon }}" /></td>
                                <td>
                                    <input name="status[{{ $m->id }}]" type="checkbox" id="switch{{ $m->id }}" switch="success" value="{{ $m->id }}" {{ $m->status ? 'checked' : '' }}/>
                                    <label for="switch{{ $m->id }}" data-on-label="是" data-off-label="否" data-size="small"></label>
                                </td>
                                <td><input type="text" class="form-control input-sm" size="1" name="sort[{{ $m->id }}]" value="{{ $m->sort }}" /></td>
                                <td>
                                    <a class="btn btn-info btn-sm show_sub" href="javascript:;" data-id="{{ $m->id }}"><i class="fa fa-eye"></i> 查看</a>
                                    <a class="btn btn-danger btn-sm permission-delete" data-href="{{ route('setting.permission.destroy',['id'=> $m->id]) }}"><i class="fa fa-trash-o"></i> 删除</a>
                                </td>
                            </tr>
                                @foreach($m->sub_permission as $sub)
                                    <tr class="parent-permission-{{ $m->id }}" style="display: none;">
                                        <td><input type="text" class="form-control input-sm" name="name[{{ $sub->id }}]" value="{{ $sub->name ? '|-- '.$sub->name : ''}}" /></td>
                                        <td>{{ $sub->namespace.'.'.$sub->controller.'.'.$sub->action }}</td>
                                        <td>{!! $sub->icon_html !!}<input type="text" class="form-control input-sm" size="1" name="icon[{{ $sub->id }}]" value="{{ $sub->icon }}" /></td>
                                        <td>
                                            <input name="status[{{ $sub->id }}]" type="checkbox" id="switch{{ $sub->id }}" switch="success" value="{{ $sub->id }}" {{ $sub->status ? 'checked' : '' }}/>
                                            <label for="switch{{ $sub->id }}" data-on-label="是" data-off-label="否" data-size="small"></label>
                                        </td>
                                        <td><input type="text" class="form-control input-sm" size="1" name="sort[{{ $sub->id }}]" value="{{ $sub->sort }}" /></td>
                                        <td>
                                        </td>
                                    </tr>
                                @endforeach
                            @endforeach
                            </tbody>
                        </table>
                        </form>
                    </div>

                </div>

            </div>
        </div>
    </div>

    <!-- end row -->
    @section('script')
        <script src="../plugins/select2/js/select2.min.js" type="text/javascript"></script>
        <script src="../plugins/bootstrap-select/js/bootstrap-select.min.js" type="text/javascript"></script>
        <script src="../plugins/moment/moment.js"></script>
        <script src="../plugins/timepicker/bootstrap-timepicker.js"></script>
        <script src="../plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js"></script>
        <script src="../plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
        <script src="../plugins/clockpicker/js/bootstrap-clockpicker.min.js"></script>
        <script src="../plugins/bootstrap-daterangepicker/daterangepicker.js"></script>
        <!-- Init js -->
        <script src="assets/pages/jquery.form-pickers.init.js"></script>
        <script src="../plugins/bootstrap-sweetalert/sweet-alert.min.js"></script>
        <script src="{{ asset('js/ajax.js') }}"></script>
        <script>
            $('.select2').select2();
            $(".btn-primary").click(function(){
                $("#form").submit();
            });
            $('.show_sub').click(function(){
                var id = $(this).data('id');
                $('.parent-permission-' + id).toggle();
            });

            $(".permission-delete").click(function () {
                Rbac.ajax.delete({
                    href: $(this).data('href'),
                    successTitle: '权限删除成功'
                });
            });

            $(".deleteall").click(function () {
                Rbac.ajax.deleteAll({
                    href: $(this).data('href'),
                    successTitle: '权限删除成功'
                });
            });
        </script>
    @endsection
@stop














